/**
 *Project: jh-framework
 *File: cn.xkshow.framework.service.UniversalService.java 
 *Author: hardy(admin@xkshow.cn) Copyright
 ****************************************************************
 *   VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *    1.0        2013-7-4         hardy         create
 ****************************************************************
 *note:
 ***************************************************************/ 
package cn.xkshow.framework.service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import cn.xkshow.framework.dao.hibernate.UniversalDao;
import cn.xkshow.plugins.page.PageList;
import cn.xkshow.plugins.page.Page;


@Service
public class UniversalService<T> {	
	private UniversalDao<T> universalDao;
	
	/**
	 **************************************
	 * save-update
	 **************************************
	 */
	public void save(Object entity) {
		this.universalDao.save(entity);
	}
	
	public void saveOrUpdate(Object entity) {
		this.universalDao.saveOrUpdate(entity);
	}
	
	/**
	 *************************************** 
	 * delete
	 *************************************** 
	 */
	public void delete(Object entity) {
		this.universalDao.delete(entity);
	}
	
	public void deleteById(Class entity, Serializable id) {
		// TODO Auto-generated method stub
		this.universalDao.deleteById(entity, id);
	}
	
	public void deleteAll(String entityName, String propertyName, Object propertyValue) {
		// TODO Auto-generated method stub
		this.universalDao.deleteAll(entityName, propertyName, propertyValue);
	}
	
	public void deleteAllByHql(String hql, Map<String, Object> paramMap) {
		this.universalDao.deleteAllByHql(hql, paramMap);
	}
	
	/** 
	 ***************************************
	 * getEntity
	 ***************************************
	 */	
	public T getEntity(Class<T> entity, Serializable value) {
		// TODO Auto-generated method stub
		return this.universalDao.getEntity(entity, value);
	}
	
	public T getEntity(Class<T> entity, String propertyName, Object propertyValue) {
		// TODO Auto-generated method stub
		return this.universalDao.getEntity(entity, propertyName, propertyValue);
	}
	
	public Object getEntityByHql(String hql, Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return this.universalDao.getEntityByHql(hql, paramMap);
	}
	
	public Object getEntityBySql(String sql, Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return this.universalDao.getEntityBySql(sql, paramMap);
	}
	
	/**
	 ***************************************
	 * getCount
	 ***************************************
	 */
	public long getCountByHql(String hql, Map<String, Object> paramMap) {		
		return this.universalDao.getCountByHql(hql, paramMap);
	}

	public long getCountBySql(String sql, Map<String, Object> paramMap) {
		return this.universalDao.getCountBySql(sql, paramMap);
	}
	
	/**
	 ***************************************
	 * findList: HQL
	 ***************************************
	 */
	public List findListByHql(String hql, Map<String, Object> paramMap) {
		return this.universalDao.findListByHql(hql, paramMap);
	}
	
	public List findListByHql(String hql, Map<String, Object> paramMap, int offset, int count) {
		return this.universalDao.findListByHql(hql, paramMap, offset, count);
	}

	public PageList findPageListByHql(String hql, Map<String, Object> paramMap, Page pages){
		return this.universalDao.findPageListByHql(hql, paramMap, pages);
	}

	/**
	 ***************************************
	 * findList: SQL
	 ***************************************
	 */
	public List findListBySql(String sql, Map<String, Object> paramMap) {
		return this.universalDao.findListBySql(sql, paramMap);
	}

	public List findListBySql(String sql, Map<String, Object> paramMap, int offset, int count) {
		return this.universalDao.findListBySql(sql, paramMap, offset, count);
	}

	public PageList findPageListBySql(String sql, Map<String, Object> paramMap, Page pages){
		return this.universalDao.findPageListBySql(sql, paramMap, pages);
	}

	public void setUniversalDao(UniversalDao<T> universalDao) {
		this.universalDao = universalDao;
	}

}
